package com.celan.year2023.month01.day24;

public class Solution {
    public int[] countPoints(int[][] points, int[][] queries) {
        int n = queries.length;
        int[] res = new int[n];
        //圆心a,b
        //(x-a)^2 + (y-b)^2 <= r^2 在园内
        for (int i = 0; i < n; i++) {
            int[] query = queries[i];
            int a = query[0];
            int b = query[1];
            int r = query[2];
            for (int[] point : points) {
                int x = point[0];
                int y = point[1];
                x = Math.abs(x - a);
                y = Math.abs(y - b);
                int distance = x * x + y * y;
                if (distance <= r * r) res[i]++;
            }
        }
        return res;
    }

    public int myAtoi(String str) {
        str = str.trim();
        if (str.length() == 0) return 0;
        if (!Character.isDigit(str.charAt(0))
                && str.charAt(0) != '-' && str.charAt(0) != '+')
            return 0;
        long ans = 0L;
        boolean neg = str.charAt(0) == '-';
        int i = !Character.isDigit(str.charAt(0)) ? 1 : 0;
        while (i < str.length() && Character.isDigit(str.charAt(i))) {
            ans = ans * 10 + (str.charAt(i++) - '0');
            if (!neg && ans > Integer.MAX_VALUE) {
                ans = Integer.MAX_VALUE;
                break;
            }
            if (neg && ans > 1L + Integer.MAX_VALUE) {
                ans = 1L + Integer.MAX_VALUE;
                break;
            }
        }
        return neg ? (int) -ans : (int) ans;
    }

    public int strStr(String haystack, String needle) {
        if (!haystack.contains(needle)) return -1;
        return haystack.indexOf(needle);
    }

    
}
